package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.impl.UserShoppingCartServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "C端-购物车接口")
@RestController
@RequestMapping("/user/shoppingCart")
public class UserShoppingCartController {

    @Autowired
    private UserShoppingCartServiceImpl userShoppingCartService;


    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result<String> insert(@RequestBody ShoppingCartDTO shoppingCartDTO){
        userShoppingCartService.insert(shoppingCartDTO);
        return Result.success();
    }

    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> list(){
        return Result.success(userShoppingCartService.list());
    }

    @ApiOperation("删除购物车中一个商品")
    @PostMapping("/sub")
    public Result<String> delete(@RequestBody ShoppingCartDTO shoppingCartDTO){
        userShoppingCartService.delete(shoppingCartDTO);
        return Result.success();
    }

    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result<String> clean(){
        userShoppingCartService.clean();
        return Result.success();
    }
}
